﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Lottery.Client.SL.Controls
{
    public partial class NavControl : UserControl
    {
        public delegate void LowerDataEventHandler(object sender, NavUserInfo nui);
        private bool _bool;
        private NavControl.LowerDataEventHandler _lowerDataEventHandler;
        private NavUserInfo _navUserInfo;
        public event NavControl.LowerDataEventHandler LowerClicked
        {
            add
            {
                NavControl.LowerDataEventHandler lowerDataEventHandler = this._lowerDataEventHandler;
                NavControl.LowerDataEventHandler lowerDataEventHandler2;
                do
                {
                    lowerDataEventHandler2 = lowerDataEventHandler;
                    NavControl.LowerDataEventHandler lowerDataEventHandler3 = (NavControl.LowerDataEventHandler)Delegate.Combine(lowerDataEventHandler2, value);
                    lowerDataEventHandler = Interlocked.CompareExchange<NavControl.LowerDataEventHandler>(ref this._lowerDataEventHandler, lowerDataEventHandler3, lowerDataEventHandler2);
                }
                while (lowerDataEventHandler != lowerDataEventHandler2);
            }
            remove
            {
                NavControl.LowerDataEventHandler lowerDataEventHandler = this._lowerDataEventHandler;
                NavControl.LowerDataEventHandler lowerDataEventHandler2;
                do
                {
                    lowerDataEventHandler2 = lowerDataEventHandler;
                    NavControl.LowerDataEventHandler lowerDataEventHandler3 = (NavControl.LowerDataEventHandler)Delegate.Remove(lowerDataEventHandler2, value);
                    lowerDataEventHandler = Interlocked.CompareExchange<NavControl.LowerDataEventHandler>(ref this._lowerDataEventHandler, lowerDataEventHandler3, lowerDataEventHandler2);
                }
                while (lowerDataEventHandler != lowerDataEventHandler2);
            }
        }
        public NavControl()
		{
			this.InitializeComponent();
		}
        private NavUserInfo InitNavUserInfo()
        {
            if (this._navUserInfo == null)
            {
                this._navUserInfo = new NavUserInfo();
                this._navUserInfo.UserId = DataCache.CurrentUserInfo.ID;
                this._navUserInfo.UserName = DataCache.CurrentUserInfo.Name;
            }
            return this._navUserInfo;
        }
        public void SetNav(List<NavUserInfo> nuis)
        {
            this.SetNav(nuis, "");
        }
        public void SetNav(List<NavUserInfo> nuis, string recordstr)
        {
            if (!string.IsNullOrEmpty(recordstr))
            {
                TextBlock textBlock = new TextBlock();
                textBlock.Tag=(this.InitNavUserInfo());
                textBlock.Style = Resources["TextBlockStyle0"] as Style;
                textBlock.MouseLeftButtonUp+=(new MouseButtonEventHandler(this.Tb_MouseLeftButtonUp));
                textBlock.Text=(this.InitNavUserInfo().UserName);
                this.LayoutRoot.Children.Clear();
                this.LayoutRoot.Children.Add(textBlock);
                if (nuis != null && nuis.Count > 0)
                {
                    for (int i = 0; i < nuis.Count; i++)
                    {
                        textBlock = new TextBlock();
                        this.LayoutRoot.Children.Add(textBlock);
                        textBlock.Style = Resources["TextBlockStyle0"] as Style;
                        textBlock.Text = "??";
                        textBlock = new TextBlock();
                        this.LayoutRoot.Children.Add(textBlock);
                        textBlock.Text = (nuis[i].UserName);
                        textBlock.Style = Resources["TextBlockStyle0"] as Style;
                        textBlock.Tag = (nuis[i]);
                        textBlock.MouseLeftButtonUp += (new MouseButtonEventHandler(this.Tb_MouseLeftButtonUp));
                    }
                }
                textBlock = new TextBlock();
                this.LayoutRoot.Children.Add(textBlock);
                textBlock.Style = Resources["TextBlockStyle0"] as Style;
                textBlock.Text = "??";
                textBlock = new TextBlock();
                textBlock.Style = Resources["TextBlockStyle0"] as Style;
                this.LayoutRoot.Children.Add(textBlock);
                textBlock.Text = (recordstr);
                return;
            }
            TextBlock textBlock2 = new TextBlock();
            textBlock2.Text = (this.InitNavUserInfo().UserName);
            this.LayoutRoot.Children.Clear();
            this.LayoutRoot.Children.Add(textBlock2);
            if (nuis != null && nuis.Count > 0)
            {
                textBlock2.Tag = (this.InitNavUserInfo());
                textBlock2.Style = Resources["TextBlockStyle0"] as Style;
                textBlock2.MouseLeftButtonUp+=(new MouseButtonEventHandler(this.Tb_MouseLeftButtonUp));
                for (int j = 0; j < nuis.Count; j++)
                {
                    textBlock2 = new TextBlock();
                    this.LayoutRoot.Children.Add(textBlock2);
                    textBlock2.Style = Resources["TextBlockStyle0"] as Style;
                    textBlock2.Text = "??";
                    textBlock2 = new TextBlock();
                    this.LayoutRoot.Children.Add(textBlock2);
                    textBlock2.Text = (nuis[j].UserName);
                    if (j == nuis.Count - 1)
                    {
                        textBlock2.Style = Resources["TextBlockStyle0"] as Style;
                    }
                    else
                    {
                        textBlock2.Style = Resources["TextBlockStyle0"] as Style;
                        textBlock2.Tag = (nuis[j]);
                        textBlock2.MouseLeftButtonUp+=(new MouseButtonEventHandler(this.Tb_MouseLeftButtonUp));
                    }
                }
                return;
            }
            textBlock2.Style = Resources["TextBlockStyle0"] as Style;
        }
        private void Tb_MouseLeftButtonUp(object obj, MouseButtonEventArgs mouseButtonEventArgs)
        {
            if (this._lowerDataEventHandler != null)
            {
                this._lowerDataEventHandler(this, (obj as TextBlock).Tag as NavUserInfo);
            }
        }
    }
}
